<?php
session_start();
require('../../connections/con_gl.php'); 
mysql_select_db($database_con_gl, $con_gl);
$area = $_REQUEST['area'];
list($namaarea) = mysql_fetch_row(mysql_query("select area from gl_area where id='$area'"));
?>
<!--<p><a style="cursor:pointer;" onclick="window.print();"><img src="images/_print.PNG" />&nbsp;&nbsp;Cetak</a></p>-->
<h3>STATUS KENDARAAN UNIT TLI <?php echo strtoupper($namaarea); ?></h3>
<table width="100%" border="1" cellspacing="0" cellpadding="3">	
	<tr style="text-align:center;background-color:#eee">
		<th width="3%">No.</th>
		<th width="30%">STOK STATUS</th>
		<?php
		$str = "select id, area from gl_area ";
		if($area!='') $str .= " where id='$area' ";
		$str .= " order by area asc ";
		$query=mysql_query($str) or die (mysql_error());
		while(list($idarea, $namaarea)=mysql_fetch_row($query)){
		echo "<th>$namaarea</th>";
		}
		?>
		<th width="10%">Total</th>
	</tr>
	<?php
	
	$status= array(1=>'Corporate',2=>'Retail',3=>'Tugas Kantor',4=>'Ops / UGC');
	$no=1;
	$totalkeseluruhan = 0;	
	foreach($status as $key=>$value)
	{
	echo "<tr>";
	echo "<td align='center'>$no.</td>";
	echo "<td align='left'>$value</td>";
	//echo "<td align='left'>$keterangan</td>";
		$str = "select id, area from gl_area ";
		if($area!='') $str .= " where id='$area' ";
		$str .= " order by area asc ";
		$querysub=mysql_query($str) or die (mysql_error());
		$total=0;
		while(list($idarea, $namaarea)=mysql_fetch_row($querysub)){
		list($jmlunit)=mysql_fetch_row(mysql_query("select count(*) from gl_masterkendaraan where area='$idarea' and unitstok='$key'"));		
		
		if($jmlunit==0)$jmlunit='';
		echo "<td align='center'>$jmlunit</td>";
		$total+=$jmlunit;
		}
		if($total==0)$total='';
		echo "<td align='center'>$total</td>";
		 	
	echo "</tr>";
	$totalkeseluruhan +=$total;	
	$no++;
	}
		
	?>
	
		<td colspan="2" align="center"><b>Total</b></td>
		<?php
		 
		
		$str = "select id, area from gl_area ";
		if($area!='') $str .= " where id='$area' ";
		$str .= " order by area asc ";
		$querysub=mysql_query($str) or die (mysql_error());
		$total=0;
		while(list($idarea, $namaarea)=mysql_fetch_row($querysub)){
		list($jmlunit)=mysql_fetch_row(mysql_query("select count(*) from gl_masterkendaraan where area='$idarea'"));		
		
		if($jmlunit==0)$jmlunit='';
		echo "<td align='center'>$jmlunit</td>";
		$total+=$jmlunit;
		}
		if($total==0)$total='';
			echo "<td align='center'>$total</td>";		

	
	

		
		?>
		
	</tr>
</table>

<div id="box-exportdata">
<a href="doc/laporanstatuskendaraanunitPDF.php?area=<?php echo $area;?>" title="Export PDF"><img src="images/_print.png" border="0" /></a><br /><br />
<a href="doc/laporanstatuskendaraanunitexcel.php?area=<?php echo $area; ?>&amp;files='Data Status Kendaraan Unit TLI'" title="Export Excel"><img src="images/_xls.png" border="0" /></a><br /><br />
<a href="doc/laporanstatuskendaraanunitdoc.php?area=<?php echo $area; ?>&amp;files='Data Status Kendaraan Unit TLI'" title="Export Word"><img src="images/_word.png" border="0" /></a>
</div>

<p>&nbsp;</p>